<#assign ctx=request.contextPath />
<!doctype html>
<html class="no-js fixed-layout">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>动态代码管理</title>
<meta name="keywords" content="index">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="${ctx}/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${ctx}/bootstrap/css/bootstrap-table.min.css" />
<style type="text/css">
</style>
</head>
<body>
	<div class="container">
		<ul class="nav nav-tabs nav-pills">
	 		<li role="presentation" class="active"><a href="${ctx}/code/index">动态代码管理</a></li>
	 		<li role="presentation"><a href="#">动态配置管理</a></li>
	 		<li role="presentation"><a href="${ctx}/app/toList">密钥管理</a></li>
		</ul>
		<div class="row" style="margin-top:10px;padding:12px;">
			<div class="well">
				<div id="toolbar" class="btn-group">
					<form class="form-inline">
						<div class="form-group">
					        <label>App：</label>
					        <select id="appId" name="appId" class="form-control">
					        		<option value="">全部</option>
									<#list registers as register>
										<option value="${register.id}" <#if (appId??)&&register.id==appId>selected="selected"</#if>>${register.appCode}__${register.appName}</option>
									</#list>
							</select>
					    </div>
						<div class="form-group">
					        <label>代码名称：</label>
					        <input id="codeName" type="text" class="form-control" placeholder="代码名称" value="<#if codeName??>${codeName}</#if>">
					    </div>
				        <button id="search" type="button" class="btn btn-primary">搜索</button>
				        <button id="reset" type="button" class="btn btn-default">重置</button>
				    </from>
					<button id="btn_add" type="button" class="btn btn-default">
						<span class="glyphicon glyphicon-plus"></span>新增
					</button>
					<button id="editInfo" type="button" class="btn btn-default">
						<span class="glyphicon glyphicon-plus"></span>编辑
					</button>
				</div>
				<table id="table"></table>
			</div>
		</div>
	</div>

	<script src="${ctx}/jquery/jquery.min.js"></script>
	<script src="${ctx}/bootstrap/js/bootstrap.min.js"></script>
	<script src="${ctx}/bootstrap/js/bootstrap-table.min.js"></script>
	<script src="${ctx}/bootstrap/local/bootstrap-table-zh-CN.min.js"></script>
	<script src="${ctx}/layer/layer.js"></script>
	<script type="text/javascript">
		$(function() {
			$('#table').bootstrapTable({
				url : '${ctx}/code/list',
				method: 'post',
				contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
				dataType : "json",
				toolbar : '#toolbar',
				pagination : true,
				sidePagination : "server",
				queryParams: function(params) {
					return {
							pageSize : params.limit, //页面大小
							pageNumber : params.offset + 1, //页码
							current: (params.limit == 0 ? 0 : params.offset/params.limit) + 1,//第几页
							appId: $("#appId").val(),
							codeName: $("#codeName").val(),
						   };
				},
				pageNumber : 1,
				pageSize : 10,
				cache : false,
				striped : true,
				clickToSelect: true,
				uniqueId : "id",
				columns : [{
					checkbox: true
				}, {
					field : 'codeName',
					title : '代码名称'
				}, {
					field : 'codeDesc',
					title : '代码描述'
				}, {
					field : 'createTime',
					title : '创建时间'
				}, {
					field:"action",
					title:"操作",
					align:"center",
					formatter:function(value,row,index){
						var strHtml ='<a href="javascript:void(0);" onclick="toView('+ row.id +')" data-toggle="tooltip" data-placement="top" title="代码查看"><li class="glyphicon glyphicon-eye-open"></li></a>    '+ 
						'<a href="javascript:void(0);" onclick="toEdit('+ row.id +')" data-placement="top" title="代码编辑" style="margin-left:5px;" ><li class="glyphicon glyphicon-pencil"></li></a>    '+ 
						'<a href="javascript:void(0);" onclick="cacheClear('+ row.id +')" data-toggle="tooltip" data-placement="top" title="清除缓存" style="margin-left:5px;" ><li class="glyphicon glyphicon-refresh"></li></a>    '+ 
						'<a href="javascript:void(0);" onclick="remove('+ row.id +')" data-toggle="tooltip" data-placement="top" title="删除" style="margin-left:5px;"><li class="glyphicon glyphicon-remove"></li></a>'; 
						return strHtml;
					}
				}]
			});
			
			$('#btn_add').click(function() {
				  layer.open({
					  type: 2,
					  title: '新增代码基本信息',
					  shadeClose: true,
					  shade: 0.8,
					  area: ['60%', '45%'],
					  content: '${ctx}/code/toAddInfo' 
					}); 
			});
			$('#search').click(function() {
				$('#table').bootstrapTable('refresh', {query: {appId: $("#appId").val(), codeName: $("#codeName").val()}});
			});
			$('#reset').click(function() {
				$("#appId").val('');
				$("#codeName").val('');
				$('#table').bootstrapTable('refresh', {query: {appId: $("#appId").val(), codeName: $("#codeName").val()}});
			});
			$('#editInfo').click(function() {
				var rows = $('#table').bootstrapTable('getSelections');
				if (rows.length == 1) {
					 layer.open({
					  type: 2,
					  title: '代码查看',
					  shadeClose: true,
					  shade: 0.8,
					  area: ['90%', '90%'],
					  content: '${ctx}/code/' + rows[0].id + '/toEditInfo' 
					}); 
				}else{
					layer.msg("你没有选择行或选择了多行数据", {icon : 0});
				}
			});
		});
		
		function remove(id) {
			layer.confirm('确认删除吗？', {
		        icon : 3,
		        title : '删除提示'
		    }, function(index, layero) {
		        $.ajax({
		            type : "DELETE",
		            url :  "${ctx}/code/" + id + "/delete",
		            dataType : "json",
		            success : function(data) {
		                if (data.status=="1") {
		                    layer.msg(data.message, {icon : 1}, function() {
		                    	parent.location.reload();
		                    });
		                } else {
		                    layer.msg(data.message, {icon : 0});
		                }
		            },
		            error : function(errorMsg) {
		                layer.msg('服务器未响应,请稍后再试', {icon : 3});
		            }
		        });
		        layer.close(index);
		    });
		};
		function cacheClear(id) {
			$.ajax({
	            type : "GET",
	            url :  "${ctx}/code/" + id + "/cacheClear",
	            dataType : "json",
	            success : function(data) {
	                 layer.msg(data.message, {icon : 1});
	            },
	            error : function(errorMsg) {
	                layer.msg('服务器未响应,请稍后再试', {icon : 3});
	            }
	        });
		};
		function toView(id) {
			 layer.open({
			  type: 2,
			  title: '代码查看',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['90%', '90%'],
			  content: '${ctx}/code/' + id + '/toView' 
			}); 
		};
		function toEdit(id) {
			 layer.open({
			  type: 2,
			  title: '代码编辑(Ctrl+S保存)',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['90%', '90%'],
			  content: '${ctx}/code/' + id + '/toEdit' 
			}); 
		};
	</script>
</body>
</html>